package com.billdowney.qq.robot.plugins.provide;

import com.billdowney.qq.robot.bean.ConfigBean;
import com.billdowney.qq.robot.enums.RobotEventEnum;
import com.billdowney.qq.robot.plugins.RobotPlugin;
import com.billdowney.qq.robot.plugins.RobotPluginContent;
import com.billdowney.qq.robot.plugins.RobotPluginInfo;
import com.billdowney.qq.robot.util.MessageUtil;
import net.mamoe.mirai.event.events.MemberJoinEvent;
import net.mamoe.mirai.message.data.At;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 群管理插件
 *
 * @author BillDowney
 * @date 2021/4/7 20:12
 */
@Component
public class GroupManageRobotPlugin implements RobotPlugin {
    @Autowired
    private ConfigBean configBean;

    @Override
    public RobotPluginInfo info() {
        return RobotPluginInfo.create("群管理插件", true)
                .addDescLn("自动欢迎入群成员：").addDescLn("暂无其它功能");
    }

    @Override
    public void execute(RobotPluginContent content) {
        if (RobotEventEnum.MEMBER_JOIN.equals(content.getRobotEventEnum())) {
            MemberJoinEvent event = (MemberJoinEvent) content.getEvent();
            MessageChainBuilder builder = MessageUtil.createBuilder();
            builder.append(new At(event.getMember().getId()));
            builder.append(MessageUtil.buildImageMessage(event.getGroup()
                    , this.getClass().getResourceAsStream("/img/join_group_welcome.jpg")));
            content.putReplyMessage(event.getGroup(), builder.build());
        }
    }
}
